﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AllenData;
using AllenNeighborhood.UI;

namespace AllenNeighborhood
{
    public partial class NeighborList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.LoadNeighbors(this.Request.QueryString["StreetNumber"], Utilities.ParseScreenInt(this.Request.QueryString["StreetID"]));
            }
        }

        private void LoadNeighbors(string streetNumber, int streetID)
        {
            var data = new NeighborData();
            this.MatchingNeighbors.DataSource = data.GetNeighbors(streetNumber, streetID);
            this.MatchingNeighbors.DataTextField = "DisplayText";
            this.MatchingNeighbors.DataValueField = "NeighborID";
            this.MatchingNeighbors.DataBind();
        }

        protected void SelectNeighborButton_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.MatchingNeighbors.SelectedValue))
            {
                this.Response.Redirect(string.Format("~/Secure/InteractionAdd.aspx?NeighborID={0}", this.MatchingNeighbors.SelectedValue));
            }
        }

        protected void AddNeighborButton_Click(object sender, EventArgs e)
        {
            this.Response.Redirect(string.Format("~/Secure/NeighborAdd.aspx?StreetNumber={0}&StreetID={1}", this.Request.QueryString["StreetNumber"], this.Request.QueryString["StreetID"]));
        }

        protected void EditNeighborButton_Click(object sender, EventArgs e)
        {
            this.Response.Redirect(string.Format("~/Secure/NeighborAdd.aspx?NeighborID={0}", this.MatchingNeighbors.SelectedValue));
        }
    }
}